<?php

/**
 * stampa actions.
 *
 * @package    dnevnik
 * @subpackage stampa
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class stampaActions extends sfActions
{
  public function executeKorPodaci(sfWebRequest $request)
  {
     $skolas = $this->getUser()->getAttribute('skolas');

     $skola_ids = array_keys($skolas);
     $skola_id = $skola_ids[0];
     if($this->getRequest()->isMethod('post') and $request->getParameter('skola_id') != '')
       $skola_id = $request->getParameter('skola_id');
     $kor_podaci = new KorisnickiPodaci($skola_id);
     $raz_select = $kor_podaci->getSkolaRazredSelect();
     $profils = array();

     if($this->getRequest()->isMethod('post'))
     {
        $tip = $request->getParameter('tip');
        if($tip == ProfilPeer::$tip['profesor'])
        {
           $profils = $kor_podaci->getProfesors();
        }

        if($tip == ProfilPeer::$tip['ucenik'])
        {
           $profils = $kor_podaci->getUceniks($request->getParameter('razred_id'));
        }

        else if($tip == ProfilPeer::$tip['roditelj'])
        {
           $profils = $kor_podaci->getRoditeljs($request->getParameter('razred_id'));
        }
     }

     $skola_list = array();
     $skola_dbs = DbFinder::from('Skola')->where('Id', 'in', array_keys($skolas))->find();
     foreach($skola_dbs as $skola_db)
       $skola_list[$skola_db->getId()] = $skola_db->getIme().' - '.$skola_db->getMesto();

     $this->skola_list = $skola_list;
     $this->profil_tips = array('' => 'Izaberi', 3 => 'Profesor', 4 => 'Roditelj', 5 => 'Učenik');
     $this->skolas = $skolas;
     $this->skola_id = $skola_id;
     $this->raz_select = $raz_select;
     $this->profils = $profils;
  }

  public function executeLoadRazreds(sfWebRequest $request)
  {
     $kor_podaci = new KorisnickiPodaci($request->getParameter('skola_id'));
     return $this->renderText($kor_podaci->getSkolaRazredSelect());
  }

  public function executeJedan(sfWebRequest $request)
  {
     $kor_podaci = new KorisnickiPodaci($request->getParameter('skola_id'));
     $pdf = $kor_podaci->pdfJedan($request->getParameter('tip'), $request->getParameter('id'));

     $this->getResponse()->setContentType('application/pdf');
     $this->getResponse()->setHttpHeader('Pragma', 'no-cache');
     $this->getResponse()->setHttpHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');

     $pdf->Output();
     return sfView::NONE;
  }

  public function executeVise(sfWebRequest $request)
  {
     $kor_podaci = new KorisnickiPodaci($request->getParameter('skola_id'));

     if($request->getParameter('tip') == ProfilPeer::$tip['profesor'])
       $pdf = $kor_podaci->pdfProfesor();
     if($request->getParameter('tip') == ProfilPeer::$tip['roditelj'])
       $pdf = $kor_podaci->pdfRoditelj($request->getParameter('razred_id'));
     if($request->getParameter('tip') == ProfilPeer::$tip['ucenik'])
       $pdf = $kor_podaci->pdfUcenik($request->getParameter('razred_id'));

     $this->getResponse()->setContentType('application/pdf');
     $this->getResponse()->setHttpHeader('Pragma', 'no-cache');
     $this->getResponse()->setHttpHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');

     $pdf->Output();
     return sfView::NONE;
  }
}